package ym.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ym.mapper.HouseBrokerMapper;
import ym.pojo.HouseBroker;
import ym.service.HouseBrokerService;

import java.util.List;

@Service
@Transactional
public class HouseBrokerServiceImpl implements HouseBrokerService {
    @Autowired
    private HouseBrokerMapper houseBrokerMapper;


    @Override
    public void add(HouseBroker houseBroker) {
        houseBrokerMapper.insert(houseBroker);
    }

    @Override
    public void update(HouseBroker houseBroker) {
        houseBrokerMapper.updateById(houseBroker);
    }

    @Override
    public void delete(Integer id) {
        houseBrokerMapper.deleteById(id);
    }

    @Override
    public HouseBroker findById(Integer id) {
        return houseBrokerMapper.selectById(id);
    }

    @Override
    public List<HouseBroker> findAll() {
        return houseBrokerMapper.selectList(null);
    }

    @Override
    public Page<HouseBroker> search(String search, int page, int size) {
        QueryWrapper<HouseBroker> queryWrapper = new QueryWrapper<>();
        if (search != null) {
            queryWrapper.like("houseBrokerName", search);
        }
        return houseBrokerMapper.selectPage(new Page(page, size), queryWrapper);
    }

}
